<template>
  <Layout>
    <Form ref="form1" :model="form1" :label-width="120">
      <Row class="query-form" style="padding-top: 15px" v-show="!switchFlag">
        <Col span="8">
          <FormItem label='单位名称：'>
            <cascaderDom ref="riskUnit" @setOrgInfo="setRiskUnit" @setOrgname="setRiskUnitName"
                         :currentOrgId="form1.riskUnit"
                         :currentOrgName="form1.riskUnitName"
                         :orgTree="true"></cascaderDom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="风险源：">
            <Input type="text" v-model="form1.riskSources"/>
          </FormItem>
        </Col>

        <Col span="8">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset('0')" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form" style="padding-top: 15px">
        <Col span="8">
          <FormItem label='单位名称：'>
            <cascaderDom ref="riskUnit1" @setOrgInfo="setRiskUnit" @setOrgname="setRiskUnitName"
                         :currentOrgId="form1.riskUnit"
                         :currentOrgName="form1.riskUnitName"
                         :orgTree="true"></cascaderDom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="风险源：">
            <Input type="text" v-model="form1.riskSources"/>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="风险等级：">
            <!-- <Input type="text" v-model="form1.rikRankId"/>-->
            <Select v-model="rikRanks" multiple style="width:100%">
              <Option v-for="item in rikRankList" :value="item" :key="item">{{ item }}</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8" offset="16">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset('0')" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
            <Button size="large" class="ivu-btn-delete" icon="md-add" @click="deleteInfos">批量删除</Button>
        <Button size="large" class="ivu-btn-delete" icon="md-add" @click="addByTemplate">导入</Button>
          <Button size="large" class="ivu-btn-delete" icon="md-add" @click="downloadTemplate">下载模板</Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" class="table" no-data-text="没有查询到相关数据!"
           :loading="loading" size="small" @on-selection-change="selectRisks"
           highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
              show-total show-sizer show-elevator/>
      </Col>
    </Row>

    <Modal :transfer=false  :closable="false" :mask-closable="false" v-model="model1" :width=1000 :title="add?'环保风险识别新增':'环保风险识别修改'"
           @on-cancel="onCancel">
      <Form ref='InputData' :model="InputData" :rules="ruleCustom" label-position="top">
        <Row style="line-height: 25px;">
          <Col span='2'>
            <b>基础信息</b>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='单位名称：' prop="riskUnit">
              <cascaderDom ref="riskUnitadd" @setOrgInfo="setRiskUnit1" @setOrgname="setRiskUnitName1"
                           :currentOrgId="InputData.enRiskInfo.riskUnit"
                           :currentOrgName="InputData.enRiskInfo.riskUnitName"
                           :orgTree="true"></cascaderDom>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='车间/部门：' prop="riskUnit2">
              <Input v-model="InputData.enRiskInfo.riskUnit2"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='发生部位：' prop="riskUnit3">
              <Input v-model="InputData.enRiskInfo.riskUnit3"/>
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='风险源/危险物质：' prop="riskSources">
              <Input v-model="InputData.enRiskInfo.riskSources"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='环境危害和途径：' prop="environmentalHazards">
              <Input v-model="InputData.enRiskInfo.environmentalHazards"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='可能发生事故事件类型：' prop="eventType">
              <Input v-model="InputData.enRiskInfo.eventType"/>
            </FormItem>
          </Col>
        </Row>
        <hr style="margin-top: 10px;color: #dcdcdc"/>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='2'>
            <b>风险评价</b>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='历史发生违法事件频次Q1：' prop="q1">
              <Select v-model="InputData.q1">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.q1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='防控措施水平Q2：' prop="q2">
              <Select v-model="InputData.q2">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.q2Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='投诉举报Q3：' prop="q3">
              <Select v-model="InputData.q3">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.q3Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='污染物排放浓度/标准值（M1）：' prop="m1">
              <Select v-model="InputData.m1">
                <Option :value="0" label="0">
                  <span>0</span>
                  <span style="float:right;color:#ccc">不涉及</span>
                </Option>
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.m1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='危险物质泄漏数量/临界值（M2）：' prop="m2">
              <Select v-model="InputData.m2">
                <Option :value="0" label="0">
                  <span>0</span>
                  <span style="float:right;color:#ccc">不涉及</span>
                </Option>
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.m2Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='经济严重性等级E：' prop="e1">
              <Select v-model="InputData.e1">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.e1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='环境影响受体严重性等级S11a：' prop="s11a">
              <Select v-model="InputData.s11a">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.s11aName }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='环境影响受体严重性等级S11b：' prop="s11b">
              <Select v-model="InputData.s11b">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.s11bName }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='社会关注度严重性等级（S12）：' prop="s12">
              <Select v-model="InputData.s12">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.s12Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='6' offset="3">
            <span>发生可能性：{{passibleCal}}</span>
          </Col>
          <Col span='6' offset="1">
            <span>后果严重性分析：{{InputData.severityCal}}</span>
          </Col>
          <Col span='6' offset="1">
            风险等级：
            <span v-if="InputData.rikColor=='红'" style="color: red">{{InputData.rikRankName}}</span>
            <span v-else-if="InputData.rikColor=='橙'"
                  style="color: orange">{{InputData.rikRankName}}</span>
            <span v-else-if="InputData.rikColor=='黄'"
                  style="color: #FDD835">{{InputData.rikRankName}}</span>
            <span v-else-if="InputData.rikColor=='蓝'" style="color: blue">{{InputData.rikRankName}}</span>
            <span v-else style="color: white">{{InputData.rikRankName}}</span>
          </Col>
        </Row>
        <hr style="margin-top: 10px;color: #dc234b"/>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='2'>
            <b>风险管控</b>
          </Col>
          <Col span='20' offset="1">
            <FormItem label='风险防范措施：' prop="manageMeasure">
              <Input v-model="InputData.enRiskManage.manageMeasure" type="textarea"
                     :autosize="{minRows:2,maxRows:5}"/>
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='责任部门：' prop="dutyOrgId">
              <Input v-model="InputData.enRiskManage.dutyOrgName"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='责任人：' prop="dutyPersonId"><!--dutyPersonId-->
              <Input v-model="InputData.enRiskManage.dutyPersonName"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
          </Col>
        </Row>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='6' offset="3">
            <FormItem label='录入人：'>
              {{ InputData.enRiskManage.recorder }}
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='录入时间：'>
              {{ InputData.enRiskManage.recordeTime }}
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' :loading="buttonLoading||InputData._disabled"
                @click="submit('InputData')">确定
        </Button>
        <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
      </div>
    </Modal>

    <Modal v-model="model2" :width=800 title="模板导入">
      <Form ref="pageModel2"  :label-width="120">
        <Row class="query-form">
          <Col span="12">
            <FormItem label="公司名称：">
              <cascaderDom ref="riskUnit"  style="width:100%" @setOrgInfo="setRiskUnitByTemplate" @setOrgname="setRiskUnitNameByTemplate"
                         :currentOrgId="riskRiskUnitByTemplate"
                         :currentOrgName="riskRiskUnitNameByTemplate"
                         :orgTree="true"></cascaderDom>
            </FormItem>
          </Col>
          <Col span="8" offset="4">
            <Upload action="" 
                :format="['xlsx']"
                :before-upload="importFileByTemplate">
                <Button class="ivu-btn-query" icon="ios-cloud-upload-outline">上传导入文件</Button>
            </Upload>
          </Col>
        </Row>
        <Row>
          <Col span="24">
            <Table height="300" no-data-text="没有查询到相关数据!"  size="small"
                   :loading="loading"
                   highlight-row stripe border :columns="columns2" width="100%" :data="riskDataByTemplate">
            </Table>
          </Col>
        </Row>
        <Row type="flex" justify="center" class="code-row-bg">
          <Col span="23">
            <div class="hint">
              <p>导入需知：</p>
              <p>1、导入模板中每一行、每一列都不能合并单元格，不能有空白项。</p>
              <p>2、M1、M2 数据不涉及时填写“0”。</p>
            </div>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
       <Button class='ivu-btn-save' :loading="buttonLoading" @click="saveRiskDatas">保存</Button>
        <Button class='ivu-btn-cancel' @click="onCancelByTemplate">取消</Button>
      </div>
    </Modal>

    <Modal :transfer=false v-model="model3" :width=1000 title="环保风险详情">
      <Form :model="InputData" label-position="top">
        <environmentalRiskApprovalDetail ref="environmentalRiskApprovalDetail" :model1="model3"
                                         :InputData="InputData"></environmentalRiskApprovalDetail>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="model3=false">关闭</Button>
      </div>
    </Modal>

  </Layout>
</template>

<script>
import {Api} from '../../../api/index.js'
import {sessionStorage} from '../../../common/cacheUtils.js';
import cascaderDom from '../../../components/cascader-dom.vue';
import environmentalRiskApprovalDetail from './environmentalRiskApprovalDetail.vue'




export default {
  components: {cascaderDom, environmentalRiskApprovalDetail},
  name: "environmentalRiskIdentification",//环境氛围风险
  data() {
    return {
        selectedDatas:[],
      riskDataByTemplate:[],
      riskEvaluationAnalysisByTemplate:[],
      riskRiskUnitByTemplate:'',
      riskRiskUnitNameByTemplate:'',
      user: sessionStorage('userId').getObject('userId'),
      switchFlag: false,
      rikRankList: ["重大", "较大", "一般", "低"],
      rikRanks: [],
      tableHeight: '', loading: false,
      form1: {
        hazardFactor: '',
        rikRankId: '',
      },
      pageSizeArray: [10, 20, 50],
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      dataTable: [],
      ruleCustom: {
        riskUnit: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskInfo.riskUnit == null || this.InputData.enRiskInfo.riskUnit == '' || this.InputData.enRiskInfo.riskUnit == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskUnit2: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskInfo.riskUnit2 == null || this.InputData.enRiskInfo.riskUnit2 == '' || this.InputData.enRiskInfo.riskUnit2 == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskUnit3: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskInfo.riskUnit3 == null || this.InputData.enRiskInfo.riskUnit3 == '' || this.InputData.enRiskInfo.riskUnit3 == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskSources: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskInfo.riskSources == null || this.InputData.enRiskInfo.riskSources == '' || this.InputData.enRiskInfo.riskSources == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        eventType: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskInfo.eventType == null || this.InputData.enRiskInfo.eventType == '' || this.InputData.enRiskInfo.eventType == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        environmentalHazards: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskInfo.environmentalHazards == null || this.InputData.enRiskInfo.environmentalHazards == '' || this.InputData.enRiskInfo.environmentalHazards == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],


        q1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        q2: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        q3: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        m1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          transform: (value) => String(value),
          required: true,
          trigger: 'change'
        }],
        m2: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          transform: (value) => String(value),
          required: true,
          trigger: 'change'
        }],
        e1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        s11a: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        s11b: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        s12: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

        manageMeasure: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskManage.manageMeasure == null || this.InputData.enRiskManage.manageMeasure == '' || this.InputData.enRiskManage.manageMeasure == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        dutyPersonId: [{
          validator: (rule, value, callback) => {
            if (this.InputData.enRiskManage.dutyPersonName == null || this.InputData.enRiskManage.dutyPersonName == '' || this.InputData.enRiskManage.dutyPersonName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
      },
      columns1: [
        {
          type: 'selection',
          width: 60,
          align: 'center',
          fixed: 'left',
        },
        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '单位名称',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskUnitName)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '车间/部门',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskUnit2)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '发生部位',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskUnit3)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '风险源/危险物质',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskSources)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '环境危害和途径',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.environmentalHazards)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '可能发生事故事件类型',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.eventType)
          }
        },
        {
          width: 150,
          title: '风险等级',
          align: 'center',
          key: 'rikRankName',
        },
        {
          width: 150,
          title: '风险防范措施',
          align: 'center',
          key: 'manageMeasure',
          render: (h, params) => {
            return h('span', params.row.enRiskManage.manageMeasure)
          },
          ellipsis: true
        },
        {
          width: 150,
          title: '责任部门',
          align: 'center',
          key: 'dutyOrgName',
          render: (h, params) => {
            return h('span', params.row.enRiskManage.dutyOrgName)
          }
        },
        {
          width: 150,
          title: '责任人',
          align: 'center',
          key: 'dutyPersonName',
          render: (h, params) => {
            return h('span', params.row.enRiskManage.dutyPersonName)
          }
        },
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 200,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('A', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                },
                on: {
                  click: () => {
                    this.InputData = params.row;
                    let recordeTime = new Date(params.row.enRiskManage.recordeTime)
                    this.InputData.enRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate()
                    this.model3 = true;
                  }
                }
              }, '详情'),
              h('Divider', {
                props: {
                  type: 'vertical',
                }
              }, ''),
              h('A', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                  color: params.row._disabled ? '#d0d0d0' : '',
                  pointerEvents: params.row._disabled ? 'none' : ''
                },
                on: {
                  click: () => {
                    this.InputData = params.row;
                    let recordeTime = new Date(params.row.enRiskManage.recordeTime)
                    this.InputData.enRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate();
                    this.model1 = true;
                    this.add = false;
                  }
                }
              }, '修改'),
              h('Divider', {
                props: {
                  type: 'vertical',
                }
              }, ''),
              h('A', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                  color: params.row._disabled ? '#d0d0d0' : 'red',
                  pointerEvents: params.row._disabled ? 'none' : ''
                },
                on: {
                  click: () => {
                    this.deleteData(params.row);
                  }
                }
              }, '删除')
            ]);
          }
        }
      ],
      add: false,
      model1: false,
      model3: false,
      InputData: {
        enRiskInfo: {},
        enRiskAssess: {},
        enRiskManage: {}
      },
      q1List: [
        {
          id: 1,
          q1Name: '过去从未发生',
          q2Name: '防控措施完全满足各方污染防控要求',
          q3Name: '过去从未发生',
          m1Name: '<0.3排放标准',
          m2Name: 'R<1',
          e1Name: '≤10',
          s11aName: '≤99',
          s11bName: '＞1000',
          s12Name: '社区乡镇',
        },
        {
          id: 2,
          q1Name: '近4年内发生一次及以上',
          q2Name: '防控措施完全满足地方污染防控要求',
          q3Name: '年内一次举报经查不属实',
          m1Name: '<0.5排放标准',
          m2Name: 'R=1',
          e1Name: '11～99',
          s11aName: '100～199',
          s11bName: '1000～800',
          s12Name: '县市'
        },
        {
          id: 3,
          q1Name: '近3年内发生一次及以上',
          q2Name: '防控措施基本满足各方污染防控要求',
          q3Name: '年内多次举报经查不属实',
          m1Name: '<0.75排放标准',
          m2Name: '1≤R<10',
          e1Name: '100～499',
          s11aName: '200～499',
          s11bName: '799～500',
          s12Name: '省市'
        },
        {
          id: 4,
          q1Name: '近2年内发生一次及以上',
          q2Name: '防控措施不能完全满足各方污染防控要求',
          q3Name: '举报并被查实的',
          m1Name: '≤1排放标准',
          m2Name: '10≤R<100',
          e1Name: '500～999',
          s11aName: '500～999',
          s11bName: '499～200',
          s12Name: '国内'
        },
        {
          id: 5,
          q1Name: '近1年内发生一次及以上',
          q2Name: '防控措施不到位或没有防控措施',
          q3Name: '多次举报并被查实的',
          m1Name: '>1排放标准',
          m2Name: '100≤R',
          e1Name: '1000以上',
          s11aName: '1000以上',
          s11bName: '＜199',
          s12Name: '国外'
        },
      ],
      riskTypeArr: [],
      buttonLoading: false,

      model2: false,
      riskPreset: [],
      columns2: [
        {
          type: 'index',
          title: '序号',
          width: 100,
          align: 'center',
        },
        {
          width: 200,
          minWidth: 150,
          title: '车间/部门',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskUnit2)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '发生部位',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskUnit3)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '风险源/危险物质',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.riskSources)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '环境危害和途径',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.environmentalHazards)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '可能发生事故事件类型',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.enRiskInfo.eventType)
          }
        },

        {
          width: 150,
          title: '风险等级',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.rikRankName)
          }
        },
        {
          width: 150,
          title: '风险防范措施',
          align: 'center',
          key: 'manageMeasure',
          render: (h, params) => {
            return h('span', params.row.enRiskManage.manageMeasure)
          },
          ellipsis: true
        },
        {
          width: 150,
          title: '责任部门',
          align: 'center',
          key: 'dutyOrgName',
          render: (h, params) => {
            return h('span', params.row.enRiskManage.dutyOrgName)
          }
        },
        {
          width: 150,
          title: '责任人',
          align: 'center',
          key: 'dutyPersonName',
          render: (h, params) => {
            return h('span', params.row.enRiskManage.dutyPersonName)
          }
        },
      ],
      reportSelectAll: [],
      riskUnits: [],
      riskUnit2s: [],
      riskUnit3s: [],
    }
  },
  watch: {
    "model1": function (qw, er) {
      if (qw && this.model1) {
        setTimeout(() => {
          this.$refs.riskUnitadd.setCurrentOrg();
        }, 100);
      } else {
        this.$refs.riskUnitadd.resetCurrentOrg();
      }
      this.openChange()
    },
  },
  mounted() {
    this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
    this.query()
    this.query1()
  },
  computed: {
    passibleCal: function () {
      let p = 0 //可能性计算
      let y = 0 //严重性计算
      let rikRan = ' '
      let rikColor = ' '
      if(this.InputData.m1 == "")
        this.InputData.m1 = 0;
      if(this.InputData.m2 == "")
        this.InputData.m2 = 0;
      if (this.InputData.q1 > 0 && this.InputData.q2 > 0 && this.InputData.q3 > 0) {
        p = Math.ceil(this.NumberAdd(this.InputData.q3, this.NumberAdd(this.InputData.q1, this.InputData.q2)) / 3)
      }
      if (this.InputData.m1 > 0 && this.InputData.m2 > 0 && this.InputData.e1 > 0 && this.InputData.s11a > 0 && this.InputData.s11b > 0 && this.InputData.s12 > 0) {
        y = Math.ceil((this.InputData.m1 + this.InputData.m2 + this.InputData.e1 + this.InputData.s11a + this.InputData.s11b + this.InputData.s12) / 6)
      }
      if (this.InputData.m1 == 0 && this.InputData.m2 > 0 && this.InputData.e1 > 0 && this.InputData.s11a > 0 && this.InputData.s11b > 0 && this.InputData.s12 > 0) {
        y = Math.ceil((this.InputData.m1 + this.InputData.m2 + this.InputData.e1 + this.InputData.s11a + this.InputData.s11b + this.InputData.s12) / 5)
      }
      if (this.InputData.m1 > 0 && this.InputData.m2 == 0 && this.InputData.e1 > 0 && this.InputData.s11a > 0 && this.InputData.s11b > 0 && this.InputData.s12 > 0) {
        y = Math.ceil((this.InputData.m1 + this.InputData.m2 + this.InputData.e1 + this.InputData.s11a + this.InputData.s11b + this.InputData.s12) / 5)
      }
      if (this.InputData.m1 == 0 && this.InputData.m2 == 0 && this.InputData.e1 > 0 && this.InputData.s11a > 0 && this.InputData.s11b > 0 && this.InputData.s12 > 0) {
        y = Math.ceil((this.InputData.m1 + this.InputData.m2 + this.InputData.e1 + this.InputData.s11a + this.InputData.s11b + this.InputData.s12) / 4)
      }
      this.InputData.severityCal = y > 0 ? y : ' ';
      this.InputData.passibleCal = p > 0 ? p : ' ';
      if (p == 0 || y == 0) {  //s5 :y r5:p
        rikRan = ' '
      } else if ((p > 2 && y == 5) || (p == 5 && y == 4)) {
        rikRan = '重大'
      } else if ((y  == 2 && p == 5) || ((p == 5 || p == 4) && y == 3) || (y == 4 && (p == 4 || p == 3)) || (p == 2 && y == 5)) {
        rikRan = '较大'
      } else if ((y == 1 && p > 3) || ((p == 3 || p == 4) && y == 2) || ((p == 2 || p == 3) && y == 3) || ((p == 2 || p== 1)&&y==4) || (p == 1 && y == 5)) {
        rikRan = '一般'
      } else {
        rikRan = '低'
      }
      rikColor = rikRan == '重大' ? '红' : rikRan == '较大' ? '橙' : rikRan == '一般' ? '黄' : rikRan == '低' ? '蓝' : ' '
      this.InputData.rikRankName = rikRan;
      this.InputData.rikColor = rikColor
      this.InputData.enRiskAssess.rikColor = rikColor
      return this.InputData.passibleCal;
    },
  },
  methods: {
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 44;
      } else {
        this.tableHeight = this.tableHeight - 44;
      }
    },
    query1() {
      let url = Api.environmentalApproval + '/' + sessionStorage('userId').getObject('userId').orgInfo.orgId
      this.$http.get(url).then((res) => {
        this.riskUnitsAll = res.data.data;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    openChange() {
      this.riskUnitsAll.forEach(item => {
        this.riskUnits.push(item.riskUnit)
        this.riskUnits = [...new Set(this.riskUnits)].filter(function (s) {
          return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
        })
        if (item.riskUnit == this.InputData.enRiskInfo.riskUnit) {
          this.riskUnit2s.push(item.riskUnit2)
          this.riskUnit2s = [...new Set(this.riskUnit2s)].filter(function (s) {
            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
          })
        }
        if (item.riskUnit2 == this.InputData.enRiskInfo.riskUnit2) {
          this.riskUnit3s.push(item.riskUnit3)
          this.riskUnit3s = [...new Set(this.riskUnit3s)].filter(function (s) {
            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
          })
        }
      })
    },
    riskUnitAdd(val) {
      this.riskUnits.push(val)
      this.riskUnit2s = []
    },
    riskUnit2Add(val) {
      this.riskUnit2s.push(val);
      this.riskUnit3s = []
    },
    riskUnit3Add(val) {
      this.riskUnit3s.push(val);
      this.riskUnit4s = []
    },
    setRiskUnit(data) {
      this.form1.riskUnit = data[data.length - 1];
    },
    setRiskUnitName(data) {
      this.form1.riskUnitName = data;
    },
    setRiskUnitByTemplate(data) {
      this.riskRiskUnitByTemplate = data[data.length - 1];
    },
    setRiskUnitNameByTemplate(data) {
      this.riskRiskUnitNameByTemplate = data;
    },
    setRiskUnit1(data) {
      this.InputData.enRiskInfo.riskUnit = data[data.length - 1];
    },
    setRiskUnitName1(data) {
      this.InputData.enRiskInfo.riskUnitName = data;
    },
    onCancel() {
      this.InputData = {
        enRiskInfo: {},
        enRiskAssess: {},
        enRiskManage: {}
      }
      this.model1 = false
      this.query()
    },
    onCancelByTemplate(){
      this.model2 = false;
    },
    submit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.buttonLoading = true
          this.InputData.enRiskManage.recordeTime = new Date(this.InputData.enRiskManage.recordeTime)
          let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
          let userId = sessionStorage('userId').getObject('userId').userId
          let url = ''
          if (this.add) {
            url = Api.environmentalAdd
            this.InputData.bsflag = '0'
            this.InputData.enRiskAssess.preset = '1'//0是预置  1不是预置
            this.InputData.createOrgId = orgId
            this.InputData.createUserId = userId
            this.InputData.enRiskInfo.createOrgId = orgId
            this.InputData.enRiskInfo.createUserId = userId
            this.InputData.enRiskAssess.createOrgId = orgId
            this.InputData.enRiskAssess.createUserId = userId
            this.InputData.enRiskManage.createOrgId = orgId
            this.InputData.enRiskManage.createUserId = userId
            this.$http.post(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.query()
              this.buttonLoading = false
            }).catch(e => {
              this.$Message.error('请求失败');
            })
            this.model1 = false
          } else {
            url = Api.environmentalUpdate;
            this.InputData.updateUserId = userId
            this.InputData.updateOrgId = orgId
            this.InputData.enRiskInfo.updateUserId = userId
            this.InputData.enRiskInfo.updateOrgId = orgId
            this.InputData.enRiskAssess.updateUserId = userId
            this.InputData.enRiskAssess.updateOrgId = orgId
            this.InputData.enRiskManage.updateUserId = userId
            this.InputData.enRiskManage.updateOrgId = orgId
            this.$http.post(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.buttonLoading = false
              this.query()
            }).catch(e => {
              this.$Message.error('请求失败');
            })
            this.model1 = false
          }
        } else {
          this.$Message.error('失败!');
        }
      })
    },
    selectRisks(items){
        this.selectedDatas = items;
    },
    deleteInfos(){
        this.$Modal.confirm({
            title: '提示',
            content: '<p>确认删除所选数据？</p>',
            onOk: () => {
                this.asyncDeleteInfo();
            }
        })
    },
     async asyncDeleteInfo(){
        this.loading = true;
         for(var i=0;i<this.selectedDatas.length;i++) {
             let url = Api.environmentalDelete + '/' + this.selectedDatas[i].envId;
             await this.$http.delete(url).then((res) => {
             }).catch(e => {
                 this.$Message.error("数据获取失败")
             })
         }
         this.query();
      },
    deleteData(row) {
      this.$Modal.confirm({
        title: '提示',
        content: '<p>确认删除此行数据？</p>',
        onOk: () => {
          let url = Api.environmentalDelete + '/' + row.envId
          this.$http.delete(url).then((res) => {
            this.$Message.success('成功');
            this.query()
          }).catch(e => {
            this.$Message.error("数据获取失败")
          })

        },
        onCancel: () => {
        }
      });

    },
    addInfo() {
      this.add = true;
      this.InputData = {
        enRiskInfo: {},
        enRiskAssess: {},
        enRiskManage: {
          recorder: sessionStorage('userId').getObject('userId').userName,
          recordeTime: new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate()
        }
      };
      this.model1 = true;
    },
    query() {
      this.loading = true;
      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize,
      }
      this.form1.orgName = sessionStorage('userId').getObject('userId').companyName
      this.form1.rikRankId = "";
      for (let i = 0; i < this.rikRanks.length; i++) {
        this.form1.rikRankId += this.rikRanks[i] + ",";
      }
      data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
      let url = Api.environmentalList
      this.$http.get(url, {params: data}).then((res) => {
          res.data.data.data.forEach(item => {
              this.rikColorChange(item);
              const sty = item.rikColor == '红' ? 'table-info-cell-red' : item.rikColor == '橙' ? 'table-info-cell-orage' : item.rikColor == '黄' ? 'table-info-cell-yellow' : item.rikColor == '蓝' ? 'table-info-cell-blue' : ''
              item.cellClassName = {rikRankName: sty}
          })
        this.dataTable = res.data.data.data;
        this.pagedata.total = res.data.data.totalSize;
        let _this = this
        this.gDic(Api.queryCodeDetailBySortId + "/risk-10005", function (result) {
          _this.riskTypeArr = result;
        });
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
      this.query1();
    },
    reset(type) {
      this.form1 = {}
      this.$refs.riskUnit.resetCurrentOrg();
      this.$refs.riskUnit1.resetCurrentOrg();
      this.rikRanks = [];
      this.pagedata.currentPage = 1
      this.query()
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.query();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.query();
    },
    changeRikRankName(val){
      if(this.InputData.rikRankName == "重大")
        this.InputData.rikColor = "红";
      else if(this.InputData.rikRankName == "较大")
        this.InputData.rikColor = "黄";
      if(this.InputData.rikRankName == "一般")
        this.InputData.rikColor = "橙";
      if(this.InputData.rikRankName == "低")
        this.InputData.rikColor = "蓝";
    },
    downloadTemplate() {
      let link = document.createElement('a');
      link.setAttribute("download", "");
      link.href = "./环保风险识别导入模板.xls"; // 你本地资源文件的存放地址
      link.click();
    },
    addByTemplate() {
      this.model2 = true;
      this.riskDataByTemplate = [];
      this.riskEvaluationAnalysisByTemplate = [];
      this.riskRiskUnitNameByTemplate = "";
      this.riskRiskUnitByTemplate = "";
    },
    async importFileByTemplate (e) {
      if(this.riskRiskUnitByTemplate == ""){
        this.$Message.error('请选择单位');
        return false;
      }
        var vali=/\.(xls|xlsx)$/;
        if(!vali.test(e.name.toLowerCase())){
            this.$Message.error('上传格式不正确，请上传xls或者xlsx格式');
            return false;
        }
        const fileReader = new FileReader();
        let this_ = this;
        fileReader.onload = function(e1) {
        try {
            const data1 = e1.target.result; // data则是我们在excel表中获取的数据
            var XLSX = require("xlsx");
            const Workbook = XLSX.read(data1, { type: 'binary'}); // 通过XLSX读取出来得到了一个 workdata 对象，下面详细介绍 workdata 对象中有些什么
            let workSheet = Workbook.Sheets[Workbook.SheetNames[0]]
            const execlDatas = XLSX.utils.sheet_to_json(workSheet);
            for(var i = 3;i < execlDatas.length; i++){
              var execlData = execlDatas[i];
              if(execlData["__EMPTY"].toString() == "" || execlData["__EMPTY_1"].toString() == ""
              || execlData["__EMPTY_2"].toString() == ""
              || execlData["__EMPTY_3"].toString() == "" || execlData["__EMPTY_4"].toString() == "" || execlData["__EMPTY_5"].toString() == ""
              || execlData["__EMPTY_6"].toString() == "" || execlData["__EMPTY_7"].toString() == "" || execlData["__EMPTY_8"].toString() == ""
              || execlData["__EMPTY_9"].toString() == "" || execlData["__EMPTY_10"].toString() == "" || execlData["__EMPTY_11"].toString() == ""
              || execlData["__EMPTY_12"].toString() == "" || execlData["__EMPTY_13"].toString() == "" || execlData["__EMPTY_14"].toString() == ""
              || execlData["__EMPTY_15"].toString() == "" || execlData["__EMPTY_16"].toString() == "")
              {
                this_.$Message.error('请上传各字段填报完整的execl文件');
                return false;
              }
              var obj = {
                "enRiskInfo":{
                  "riskUnit": this_.riskRiskUnitByTemplate,
                  "riskUnit2" : execlData["__EMPTY"],
                  "riskUnit3": execlData["__EMPTY_1"],
                  "riskSources": execlData["__EMPTY_2"],
                  "environmentalHazards": execlData["__EMPTY_3"],
                  "eventType": execlData["__EMPTY_4"],
                },
                "q1": execlData["__EMPTY_5"],
                "q2": execlData["__EMPTY_6"],
                "q3": execlData["__EMPTY_7"],
                "m1": execlData["__EMPTY_8"],
                "m2": execlData["__EMPTY_9"],
                "e1": execlData["__EMPTY_10"],
                "s11a": execlData["__EMPTY_11"],
                "s11b": execlData["__EMPTY_12"],
                "s12": execlData["__EMPTY_13"],
                "enRiskManage":{
                  "manageMeasure": execlData["__EMPTY_14"],
                  "dutyOrgName": execlData["__EMPTY_15"],
                  "dutyPersonName": execlData["__EMPTY_16"],
                  "recorder": sessionStorage('userId').getObject('userId').userName,
                  "recordeTime": new Date()
                },
                "enRiskAssess":{
                },
                "createUserId":sessionStorage('userId').getObject('userId').userId,
                "createDate": this_.formatDate(new Date(), 'yyyy-MM-dd')
              };
              let p = 0 //可能性计算
              let y = 0 //严重性计算
              let rikRan = ' '
              let rikColor = ' '
              if(obj.m1 == "")
                obj.m1 = 0;
              if(obj.m2 == "")
                obj.m2 = 0;
              if (obj.q1 > 0 && obj.q2 > 0 && obj.q3 > 0) {
                p = Math.ceil(this_.NumberAdd(obj.q3, this_.NumberAdd(obj.q1, obj.q2)) / 3)
              }
              if (obj.m1 > 0 && obj.m2 > 0 && obj.e1 > 0 && obj.s11a > 0 && obj.s11b > 0 && obj.s12 > 0) {
                y = Math.ceil((obj.m1 + obj.m2 + obj.e1 + obj.s11a + obj.s11b + obj.s12) / 6)
              }
              if ( (obj.m1 == "" || obj.m1 == 0) && obj.m2 > 0 && obj.e1 > 0 && obj.s11a > 0 && obj.s11b > 0 && obj.s12 > 0) {
                y = Math.ceil((obj.m1 + obj.m2 + obj.e1 + obj.s11a + obj.s11b + obj.s12) / 5)
              }
              if (obj.m1 > 0 && (obj.m2 == "" || obj.m2 == 0) && obj.e1 > 0 && obj.s11a > 0 && obj.s11b > 0 && obj.s12 > 0) {
                y = Math.ceil((obj.m1 + obj.m2 + obj.e1 + obj.s11a + obj.s11b + obj.s12) / 5)
              }
              if ((obj.m1 == "" || obj.m1 == 0) && (obj.m2 == "" || obj.m2 == 0) && obj.e1 > 0 && obj.s11a > 0 && obj.s11b > 0 && obj.s12 > 0) {
                y = Math.ceil((obj.m1 + obj.m2 + obj.e1 + obj.s11a + obj.s11b + obj.s12) / 4)
              }
              obj.severityCal = y > 0 ? y : ' ';
              obj.passibleCal = p > 0 ? p : ' ';
              if (p == 0 || y == 0) {  //s5 :y r5:p
                rikRan = ' '
              } else if ((p > 2 && y == 5) || (p == 5 && y == 4)) {
                rikRan = '重大'
              } else if ((y  == 2 && p == 5) || ((p == 5 || p == 4) && y == 3) || (y == 4 && (p == 4 || p == 3)) || (p == 2 && y == 5)) {
                rikRan = '较大'
              } else if ((y == 1 && p > 3) || ((p == 3 || p == 4) && y == 2) || ((p == 2 || p == 3) && y == 3) || ((p == 2 || p== 1)&&y==4) || (p == 1 && y == 5)) {
                rikRan = '一般'
              } else {
                rikRan = '低'
              }
              rikColor = rikRan == '重大' ? '红' : rikRan == '较大' ? '橙' : rikRan == '一般' ? '黄' : rikRan == '低' ? '蓝' : ' '
              obj.rikRankName = rikRan;
              obj.rikColor = rikColor
              obj.enRiskAssess.rikColor = rikColor
              this_.riskDataByTemplate.push(obj);
            }
           this_.loading = false;
        } catch (e) {
            this_.$Message.error('请上传内容符合格式的execl文件');
            return false;  
        }};
        fileReader.readAsBinaryString(e);
        return false;
    },
    saveRiskDatas(){
      this.buttonLoading = true;
      let url = Api.environmentalAddByTemplate;
      this.$http.post(url, this.riskDataByTemplate).then((res) => {
        this.$Message.success('成功');
        this.model2 = false;
        this.buttonLoading = false
        this.query()
      }).catch(e => {
        this.$Message.error("保存异常")
      })
    },
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
          'M+': date.getMonth() + 1,
          'd+': date.getDate(),
          'h+': date.getHours(),
          'm+': date.getMinutes(),
          's+': date.getSeconds()
      };
      for (let k in o) {
          if (new RegExp(`(${k})`).test(fmt)) {
              let str = o[k] + '';
              fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
          }
      }
      return fmt;
  },
  padLeftZero(str) {
      return ('00' + str).substr(str.length);
  },
  rikColorChange(row) {
      let p = 0 //可能性计算
      let y = 0 //严重性计算
      let rikRan = ' '
      let rikColor = ' '
      if(row.m1 == "" || row.m1 == null)
        row.m1 = 0;
      if(row.m2 == "" || row.m2 == null)
        row.m2 = 0;
      if (row.q1 > 0 && row.q2 > 0 && row.q3 > 0) {
        p = Math.ceil(this.NumberAdd(row.q3, this.NumberAdd(row.q1, row.q2)) / 3)
      }
      if (row.m1 > 0 && row.m2 > 0 && row.e1 > 0 && row.s11a > 0 && row.s11b > 0 && row.s12 > 0) {
        y = Math.ceil((row.m1 + row.m2 + row.e1 + row.s11a + row.s11b + row.s12) / 6)
      }
      if ( (row.m1 == "" || row.m1 == 0) && row.m2 > 0 && row.e1 > 0 && row.s11a > 0 && row.s11b > 0 && row.s12 > 0) {
        y = Math.ceil((row.m1 + row.m2 + row.e1 + row.s11a + row.s11b + row.s12) / 5)
      }
      if (row.m1 > 0 &&  (row.m2 == "" || row.m2 == 0) && row.e1 > 0 && row.s11a > 0 && row.s11b > 0 && row.s12 > 0) {
        y = Math.ceil((row.m1 + row.m2 + row.e1 + row.s11a + row.s11b + row.s12) / 5)
      }
      if ( (row.m1 == "" || row.m1 == 0) &&  (row.m2 == "" || row.m2 == 0) && row.e1 > 0 && row.s11a > 0 && row.s11b > 0 && row.s12 > 0) {
        y = Math.ceil((row.m1 + row.m2 + row.e1 + row.s11a + row.s11b + row.s12) / 4)
      }
      row.severityCal = y > 0 ? y : ' ';
      row.passibleCal = p > 0 ? p : ' ';
      if (p == 0 || y == 0) {  //s5 :y r5:p
        rikRan = ' '
      } else if ((p > 2 && y == 5) || (p == 5 && y == 4)) {
        rikRan = '重大'
      } else if ((y  == 2 && p == 5) || ((p == 5 || p == 4) && y == 3) || (y == 4 && (p == 4 || p == 3)) || (p == 2 && y == 5)) {
        rikRan = '较大'
      } else if ((y == 1 && p > 3) || ((p == 3 || p == 4) && y == 2) || ((p == 2 || p == 3) && y == 3) || ((p == 2 || p== 1)&&y==4) || (p == 1 && y == 5)) {
        rikRan = '一般'
      } else {
        rikRan = '低'
      }
      rikColor = rikRan == '重大' ? '红' : rikRan == '较大' ? '橙' : rikRan == '一般' ? '黄' : rikRan == '低' ? '蓝' : ' '
      row.rikRankName = rikRan;
      row.rikColor = rikColor
      row.enRiskAssess.rikColor = rikColor
      return row.rikRankName;
    },
  }
}
</script>

<style scoped>
@import '../../../index.css';

.hint > p {
  color: red;
}
</style>
